﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace JTicket.UI
{
    public partial class JT_ProxySet : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                Bind();
        }
        void Bind()
        {


            List<string> list = new List<string>();
            if (!string.IsNullOrEmpty(Request.QueryString["ID"].ToString()))
            {
                string thcode = Request.QueryString["ID"].ToString();
                BLL.C_TheaterInfo bllTheaterInfo = new BLL.C_TheaterInfo();
                Model.C_TheaterInfo x = bllTheaterInfo.GetModel(thcode);
                this.Label1.Text = x.ThName;
                this.Label2.Text = x.ThCode;

                if (x.Proxy != null)
                {
                    string[] str = x.Proxy.Split(new[] { ',', '|' });

                    if (str.Length > 0)
                    {
                        for (int i = 0; i <= str.Length - 1; i++)
                        {
                            list.Add(str[i]);
                        }
                    }
                }
                List<Model.C_TheaterInfo> theater2 = BLL.C_TheaterInfo.GetListContent(list);
                this.ListBox2.DataSource = theater2;
                this.ListBox2.DataTextField = "ThName";
                this.ListBox2.DataValueField = "ThCode";
                this.ListBox2.DataBind();
            }

            List<Model.C_TheaterInfo> theater = BLL.C_TheaterInfo.GetListContent2(list);
            this.ListBox1.DataSource = theater;
            this.ListBox1.DataTextField = "ThName";
            this.ListBox1.DataValueField = "ThCode";
            this.ListBox1.DataBind();
        }
        protected void Button1_Click(object sender, EventArgs e)
        {


            int i = 0;
            while (i < ListBox1.Items.Count)
            {
                if (ListBox1.Items[i].Selected == true)
                {
                    ListBox2.Items.Add(ListBox1.Items[i]);
                    ListBox1.Items.Remove(ListBox1.Items[i]);
                }
                else
                    i += 1;
            }

        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            int i = 0;
            while (i < ListBox2.Items.Count)
            {
                if (ListBox2.Items[i].Selected == true)
                {
                    ListBox1.Items.Add(ListBox2.Items[i]);
                    ListBox2.Items.Remove(ListBox2.Items[i]);
                }
                else
                    i += 1;
            }
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["ID"].ToString()))
            {
                if (ListBox2.Items.Count > 0)
                {
                    string proxy = string.Empty;
                    for (int i = 0; i < ListBox2.Items.Count;i++ )
                    {
                        proxy += ListBox2.Items[i].Value + "|";
                    }
                    Model.C_TheaterInfo theater = new Model.C_TheaterInfo();
                    theater.ThCode = Request.QueryString["ID"].ToString();
                    theater.Proxy = proxy.TrimEnd(new[]{' ','|',','});
                    BLL.C_TheaterInfo.Updates(theater); 
                }
            }
            Common.JsMsg.Alert("保存成功！");
        }
    }

}